package com.lfs.market.config;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import com.lfs.market.model.entity.SystemRole;
import com.lfs.market.model.entity.SystemUser;
import com.lfs.market.service.SystemRoleService;
import com.lfs.market.service.SystemUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


@Component
public class StpRole implements StpInterface {

    @Autowired
    private SystemUserService systemUserService;
    @Autowired
    private SystemRoleService systemRoleService;

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        String userId = StpUtil.getLoginIdAsString();
        SystemUser systemUser = systemUserService.getById(userId);

        List<SystemRole> systemRoleList = systemRoleService.lambdaQuery().eq(SystemRole::getId, systemUser.getRoleId()).list();
        List<String> roleList = new ArrayList<>();
        for (SystemRole systemRole : systemRoleList) {
            roleList.add(systemRole.getRoleCode());
        }
        return roleList;
    }

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return null;
    }
}
